<template>
  <BiFormItem :label="label || '订单时间'">
    <template slot="content">
      <!-- value-format="yyyy-MM-dd HH:mm:ss :value-format="type?'yyyy-MM-dd HH:mm:ss':'yyyy-MM-dd'"  format="yyyy-MM-dd HH:mm:ss"" :default-time="['00:00:00', '23:59:59']" -->
      <BiDatePicker
        v-model="dateValue"
        size="small"
        :clearable="clearable === false ? false :true "
        :type="type || 'daterange'"
        format="yyyy-MM-dd"
        value-format="yyyy-MM-dd"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        @change="selectChange"
      />
    </template>
  </BiFormItem>
</template>
<script>
export default {
  props: ['label', 'isResize', 'defaultValue', 'type', 'clearable'],
  data() {
    return {
      dateValue: []
    }
  },
  watch: {
    // 监听是否重置
    isResize(newVal, oldVal) {
      if (newVal) {
        this.dateValue = ''
      }
    },
    defaultValue(newVal) {
      if (newVal) {
        this.dateValue = newVal
      }
    }
  },
  mounted() {
    this.defaultValue ? (this.dateValue = this.defaultValue) : ''
  },
  methods: {
    selectChange(value) {
      if (this.dateValue) {
        this.$emit('result', { start_date: this.dateValue[0], end_date: this.dateValue[1] })
      } else {
        this.$emit('result', { start_date: '', end_date: '' })
      }
    }
  }
}
</script>

<style>
</style>